home *** CD-ROM | disk | FTP | other *** search
- program SplitbarTest;
- {Program name:SplitbarTest.Pas }
- {Function: This is a demo application of the Splitbar CDEF (ID = 17). }
- {History: 3/14/89 Original by Prototyper. }
- {Modified to work right: By Kirk Chase }
-
- uses
- Test_Window, MyGlobals, MyScroll;
-
- var
- myEvent: EventRecord; {Event record for all events}
- doneFlag: boolean; {Exit program flag}
- code: integer; {Determine event type}
- SavePort, whichWindow: WindowPtr; {See which window for event}
- tempRect, GrowRect, DragRect: Rect; {Rect for dragging}
- mResult: longint; {Menu list and item selected values}
- theMenu, theItem: integer; {Menu list and item selected}
- chCode: integer; {Key code}
- ch: char; {Key pressed in Ascii}
- IBeam: CursHandle; {IBeam Cursor}
- sleep: integer; {MF sleep period}
- DoIt: boolean;
- ResumePeek: WindowPeek;
- sysResult: boolean;
-
- procedure D_About; {puts up About Box}
- var
- GetSelection: DialogPtr; {Name of dialog}
- ItemHit: integer;
- ExitDialog: boolean; {Flag used to exit the Dialog}
-
- begin {Start of dialog handler}
- GetSelection := GetNewDialog(AboutDialogID, nil, Pointer(-1)); {Bring in the dialog resource}
- ShowWindow(GetSelection);
- SelectWindow(GetSelection);
- SetPort(GetSelection);
- ExitDialog := FALSE; {Do not exit dialog handle loop yet}
- repeat {Start of dialog handle loop}
- ModalDialog(nil, itemHit); {Wait until an item is hit}
- if (ItemHit = About_OK) then {Handle the Button being pressed}
- begin
- ExitDialog := TRUE; {Exit the dialog when this selection is made}
- end;
- until ExitDialog;
- DisposDialog(GetSelection); {Flush the dialog out of memory}
- end; {of D_About}
-
- procedure Init_My_Menus; {Initialize the menus}
- begin
- ClearMenuBar; {Clear any old menu bars}
-
- AppleMenuHandle := GetMenu(AppleMenuID); {Get the menu from the resource file}
- AddResMenu(AppleMenuHandle, 'DRVR'); {Add in DAs}
- InsertMenu(AppleMenuHandle, 0); {Insert this menu into the menu bar}
-
- FileMenuHandle := GetMenu(FileMenuID); {Get the menu from the resource file}
- InsertMenu(FileMenuHandle, 0); {Insert this menu into the menu bar}
-
- EditMenuHandle := GetMenu(EditMenuID); {Get the menu from the resource file}
- InsertMenu(EditMenuHandle, 0); {Insert this menu into the menu bar}
-
- DrawMenuBar; {Draw the menu bar}
- end; {of Init_My_Menus}
-
- procedure FixMenus; {adjust menu items such as New and Copy}
- begin
- if (FrontWindow <> nil) then {is there a front window?}
- begin
- if (FrontWindow <> MyWindow) then {is the front window mine?}
- begin {somebody else's window is in front}
- DisableItem(FileMenuHandle, C_New);
- DisableItem(FileMenuHandle, C_Close);
- EnableItem(EditMenuHandle, C_Cut);
- EnableItem(EditMenuHandle, C_Copy);
- EnableItem(EditMenuHandle, C_Paste);
- end
- else {my window is up in front}
- begin
- EnableItem(FileMenuHandle, C_Close);
- DisableItem(FileMenuHandle, C_New);
-
- DisableItem(EditMenuHandle, C_Undo);
-
- if (EditText^^.selStart <> EditText^^.selEnd) then {is there an non empty selection?}
- begin {non empty selection}
- EnableItem(EditMenuHandle, C_Cut);
- EnableItem(EditMenuHandle, C_Copy);
- end
- else
- begin
- DisableItem(EditMenuHandle, C_Cut);
- DisableItem(EditMenuHandle, C_Copy);
- end;
-
- if (TEGetScrapLen <> 0) then {is there some TE Scrap?}
- EnableItem(EditMenuHandle, C_Paste) {something there}
- else
- DisableItem(EditMenuHandle, C_Paste); {nothing there}
- end;
- end
- else
- begin {no front window}
- DisableItem(EditMenuHandle, C_Cut);
- DisableItem(EditMenuHandle, C_Copy);
- DisableItem(EditMenuHandle, C_Paste);
- DisableItem(FileMenuHandle, C_Close);
- EnableItem(FileMenuHandle, C_New);
- end;
- end; {of FixMenus}
-
- procedure FixCursor; {Non MF Cursor adjust}
- var
- mousept: Point;
- ContentRect: Rect;
- begin
- if FrontWindow = nil then
- InitCursor
- else if FrontWindow = MyWindow then
- begin
- GetMouse(mousept);
- ContentRect := MyWindow^.portRect;
- ContentRect.right := Split^^.contrlRect.left;
- ContentRect.bottom := ContentRect.bottom - SBarWidth;
- if (PtInRect(mousePt, ContentRect)) then
- SetCursor(IBeam^^)
- else
- InitCursor;
- end;
- end; {of FixCursor}
-
- procedure Handle_My_Menu (var doneFlag: boolean; theMenu, theItem: integer); {Handle menu selections}
- var
- DNA: integer; {For opening DAs}
- BoolHolder: boolean; {For SystemEdit result}
- DAName: Str255; {For getting DA name}
- SavePort: GrafPtr; {Save current port when opening DAs}
-
- begin {Start of procedure}
- case theMenu of {Do selected menu list}
- AppleMenuID:
- begin
- case theItem of {Handle all commands in this menu list}
- About_Splitbar:
- begin
- D_About; {Call a dialog for this menu selection}
- end;
- otherwise {Handle the DAs}
- begin {Start of Otherwise}
- GetPort(SavePort); {Save the current port}
- GetItem(AppleMenuHandle, theItem, DAName); {Get the name of the DA selected}
- DNA := OpenDeskAcc(DAName); {Open the DA selected}
- SetPort(SavePort); {Restore to the saved port}
- end;
- end; {End of item case}
- end; {End for this list}
-
- FileMenuID:
- begin
- case theItem of {Handle all commands in this menu list}
- C_New:
- begin
- Open_Test_Window; {Call a window for this menu selection}
- end;
- C_Close:
- begin
- Close_Test_Window(MyWindow);
- end;
- C_Quit:
- begin
- doneFlag := TRUE;
- end;
- end; {End of item case}
- end; {End for this list}
-
- EditMenuID:
- begin
- BoolHolder := SystemEdit(theItem - 1); {Do DA editing}
- if not (BoolHolder) then {If not a DA then we get it}
- begin {Handle by using a Case statment}
- case theItem of {Handle all commands in this menu list}
- C_Undo:
- begin
- end;
- C_Cut:
- begin
- ScrollToSelection;
- TECut(EditText); {Handle a Cut in a TE area}
- AdjustScrollBars;
- AdjustText(1);
- AdjustText(2);
- UpdateOtherPane;
- ScrollToSelection;
- end;
- C_Copy:
- begin
- ScrollToSelection;
- TECopy(EditText); {Handle a Copy in a TE area}
- UpdateOtherPane;
- ScrollToSelection;
- end;
- C_Paste:
- begin
- ScrollToSelection;
- TEPaste(EditText); {Handle a Paste in a TE area}
- AdjustScrollBars;
- AdjustText(1);
- AdjustText(2);
- UpdateOtherPane;
- ScrollToSelection;
- end;
- end; {End of item case}
- end; {End of not BoolHolder}
- end; {End for this list}
- end; {End for lists}
-
- HiliteMenu(0); {Turn menu selection off}
- end; {of Handle_My_Menu}
-
- procedure InitMac; {Initialize Mac Stuff}
- var
- MPtr: ^integer;
- begin
- MoreMasters;
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- FlushEvents(everyEvent, 0);
- InitCursor;
-
- MPtr := pointer(mbarHeightGlobal);
- mBarHeight := MPtr^;
- end; {of InitMac}
-
- procedure InitApp; {Initialize Application Stuff}
- begin
- doneFlag := FALSE; {Do not exit program yet}
- Init_My_Menus; {Initialize menu bar}
- IBeam := GetCursor(IBeamCursor); {Get IBeam Cursor}
-
- DragRect := screenbits.bounds; {set drag rect}
- InsetRect(DragRect, 10, 10);
- DragRect.top := DragRect.top + mBarHeight;
-
- theErr := SysEnvirons(1, theWorld);
- if (theWorld.machineType >= 0) and (NGetTrapAddress(WNETrapNum, ToolTrap) = NGetTrapAddress(UnImplTrapNum, ToolTrap)) then
- WNE := false
- else
- WNE := true;
- sleep := 10;
-
- if TEFromScrap <> noErr then {get TE Scrap from Scrap Handler}
- TESetScrapLen(0);
-
- EditText := nil; {Init EditText TE Record}
- MyWindow := nil; {Initialize the window}
- end; {of InitApp}
-
- {===================================================}
- begin {of main program}
- InitMac;
- InitApp;
-
- Open_Test_Window; {Open the window routines at program start}
-
- repeat {Start of main event loop}
- FixCursor;
- FixMenus;
-
- if (EditText <> nil) then {See if a TE is active}
- TEIdle(EditText); {Blink the cursor if everything is ok}
-
- if WNE then
- DoIt := WaitNextEvent(everyEvent, myEvent, sleep, nil)
- else
- begin
- SystemTask;
- DoIt := GetNextEvent(everyEvent, myEvent);
- end;
- if DoIt then {If event then...}
- begin {Start handling the event}
- code := FindWindow(myEvent.where, whichWindow); {Get which window the event happened in}
-
- case myEvent.what of {Decide type of event}
- MouseDown: {Mouse button pressed}
- begin {Handle the pressed button}
- if (code = inMenuBar) then {See if a menu selection}
- begin {Get the menu selection and handle it}
- mResult := MenuSelect(myEvent.Where); {Do menu selection}
- theMenu := HiWord(mResult); {Get the menu list number}
- theItem := LoWord(mResult); {Get the menu list item number}
- Handle_My_Menu(doneFlag, theMenu, theItem); {Handle the menu}
- end; {of inMenuBar}
-
- if (code = InDrag) then {See if in a window drag area}
- begin {Do dragging the window}
- DragWindow(whichWindow, myEvent.where, DragRect); {Drag the window}
- end; {of InDrag}
-
- if (code = inGrow) then {In a grow area of the window}
- begin {Handle the growing}
- EraseRect(Split^^.contrlRect); {Erase the old bottom edge}
-
- SetRect(GrowRect, 55, 55 + Split^^.contrlValue, 1000, 1000); {Min Horz size, Min Vert size, Max Horz size, Max Vert size}
- mResult := GrowWindow(whichWindow, myEvent.where, GrowRect); {Grow it}
- SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE); {Resize to result}
- FixScrollbarRects;
- DrawGrowIcon(whichWindow); {Draw the grow Icon again}
- AdjustScrollBars;
- DrawControls(MyWindow);
- AdjustText(1);
- AdjustText(2);
- ScrollToSelection;
- end; {of doing the growing}
-
- if (code = inGoAway) then {See if in a window goaway area}
- begin {Handle the goaway button}
- if TrackGoAway(whichWindow, myEvent.where) then {See if mouse released in GoAway box}
- begin {Handle the GoAway}
- Close_Test_Window(MyWindow);
- end; {End of TrackGoAway}
- end; {of InGoAway}
-
- if (code = inContent) then {See if in a window}
- begin {Handle the hit inside a window}
- if (whichWindow <> FrontWindow) then {See if already selected or not, in front if selected}
- SelectWindow(whichWindow) {Select this window to make it active}
- else {If already in front the already selected}
- begin {Handle the button in the content}
- SetPort(whichWindow); {Get ready to draw in this window}
- Do_Test_Window(myEvent); {Handle this window}
- end; {End of else}
- end; {End of inContent}
-
- if (code = inSysWindow) then {See if a DA selection}
- SystemClick(myEvent, whichWindow); {Let other programs in}
-
- end; {of MouseDown}
-
- KeyDown, AutoKey: {Handle key inputs}
- begin {Get the key and handle it}
- with myevent do {Check for menu command keys}
- begin {}
- chCode := BitAnd(message, CharCodeMask); {Get character}
- ch := CHR(chCode); {Change to ASCII}
- if (Odd(modifiers div CmdKey)) then {See if Command key is down}
- begin {}
- mResult := MenuKey(ch); {See if menu selection}
- theMenu := HiWord(mResult); {Get the menu list number}
- theItem := LoWord(mResult); {Get the menu item number}
- if (theMenu <> 0) then {See if a list was selected}
- Handle_My_Menu(doneFlag, theMenu, theItem); {Do the menu selection}
-
- end {}
- else if (EditText <> nil) then {}
- begin
- TEDeactivate(EditText);
- TEKey(ch, EditText); {}
- TEActivate(EditText);
- ScrollToSelection;
- UpdateOtherPane;
- end;
- end; {End for with}
- end; {of KeyDown,AutoKey}
-
- UpDateEvt: {Update event for a window}
- begin {Handle the update}
- whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
- if whichWindow = MyWindow then
- begin
- GetPort(SavePort); {Save the current port}
- SetPort(MyWindow); {Set the port to my window}
- BeginUpdate(whichWindow); {Set the clipping to the update area}
- Update_Test_Window; {Update this window}
- EndUpdate(whichWindow); {Return to normal clipping area}
- SetPort(SavePort); {Restore the old port}
- end;
- end; {of UpDateEvt}
-
- ActivateEvt: {Window activated event}
- begin {Handle the activation}
- whichWindow := WindowPtr(myevent.message); {Get the window to be activated}
- if odd(myEvent.modifiers) then {Make sure it is Activate and not DeActivate}
- SelectWindow(whichWindow); {Activate the window by selecting it}
- end; {of ActivateEvt}
-
- MultiEvt:
- begin
- if Odd(myEvent.message) then
- begin {resume event}
- if FrontWindow = MyWindow then
- begin
- SetPort(MyWindow);
- InvalRect(MyWindow^.portRect);
- FixMenus;
- end
- else if FrontWindow <> nil then
- begin
- ResumePeek := WindowPeek(FrontWindow);
- if ResumePeek^.windowKind < 0 then
- begin
- myEvent.what := activateEvt;
- BitSet(@myEvent.modifiers, bit0);
- sysResult := SystemEvent(myEvent);
- end;
- end;
- end {of resume event}
-
- else {suspend event}
- begin
- if FrontWindow = MyWindow then
- begin
- SetPort(MyWindow);
- InvalRect(MyWindow^.portRect);
- EnableItem(EditMenuHandle, C_Undo);
- EnableItem(EditMenuHandle, C_Cut);
- EnableItem(EditMenuHandle, C_Copy);
- EnableItem(EditMenuHandle, C_Paste);
- DrawGrowIcon(MyWindow);
- end
- else if FrontWindow <> nil then
- begin
- ResumePeek := WindowPeek(FrontWindow);
- if ResumePeek^.windowKind < 0 then
- begin
- myEvent.what := activateEvt;
- BitClr(@myEvent.modifiers, bit0);
- sysResult := SystemEvent(myEvent);
- end;
- end;
- end;
- end; {of MultiEvt}
-
- otherwise {Used for debugging, to see what other events are coming in}
- begin {}
- end; {End of otherwise}
-
- end; {End of case}
-
- end; {end of GetNextEvent}
- until doneFlag; {End of the event loop}
-
- end. {End of the program}